package com.marvels.approve.credit.controller;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.fintech.datagroud.dao.moxie.IntMxCallDetailsMapper;
import com.fintech.third.model.credit.CallCountDto;
import com.fintech.third.model.credit.CreditReportMessageDto;
import com.fintech.third.model.credit.CreditReportPortrait;
import com.fintech.third.model.credit.ZXPersonalLoanApplyInfo;
import com.fintech.third.model.credit.ZXPersonalLoanOrderInfo;
import com.fintech.third.model.credit.ZXpersonalLoanOrderDetailsInfo;
import com.fintech.third.model.moxie.dataprovide.IntMxCallDetails;
import com.fintech.third.service.credit.CreditReportService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.marvels.approve.common.dao.McamLoanApplyInfoCommonDao;
import com.marvels.approve.credit.dto.CreditExcelDTO;
import com.marvels.approve.credit.dto.CreditRepotOperatorDto;
import com.marvels.approve.credit.dto.EdcBurialPointMsgDTO;
import com.marvels.approve.credit.service.ApproveThirdCreditReportService;
import com.marvels.approve.loan.dto.McamLoanApplyInfoDTO;
import com.marvels.approve.loan.service.IMcamLoanApplyInfoService;
import com.marvels.approve.process.dto.HandleProcessDTO;
import com.marvels.approve.process.dto.LaAttachAtmeTypeViewDTO;
import com.marvels.approve.process.dto.LoanApplyCaseDTO;
import com.marvels.approve.process.dto.ScreenshotsDTO;
import com.marvels.approve.process.service.ILoanApplyCaseService;
import com.marvels.common.constants.CaseNodeConstant;
import com.marvels.common.constants.LoanStateConstant;
import com.marvels.common.constants.MarvelsConstant;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.loanapply.channel.dto.UserChannelInfoResultDTO;

import cn.hutool.core.date.DateUtil;


@RestController
@RequestMapping("/approve/credit/report/service")
public class ApproveCreditReportController {
	
	@Autowired
	private ApproveThirdCreditReportService thirdCreditReportService;
	@Autowired
	private ILoanApplyCaseService loanApplyCaseService;
	@Autowired
	com.marvels.approve.credit.service.CreditReportService creditReportService1;
	@Autowired
	McamLoanApplyInfoCommonDao mcamLoanApplyInfoCommonDao;
	@Autowired
	private IMcamLoanApplyInfoService mcamLoanApplyInfoService;
	@Autowired
	private IntMxCallDetailsMapper intMxCallDetailsMapper;
	
	
	@RequestMapping("getUserOperatorSummary/{loanId}")
	public MarvelsResultDTO getUserOperatorSummary(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getUserOperatorSummary(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("selectCallLocationPercent/{loanId}")
	public MarvelsResultDTO selectCallLocationPercent(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectCallLocationPercent(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("selectCallTypePercent/{loanId}")
	public MarvelsResultDTO selectCallTypePercent(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectCallTypePercent(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallCount/{loanId}")
	public MarvelsResultDTO getCallCount(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallCount(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallCountWithMonth/{loanId}/{month}")
	public MarvelsResultDTO getCallCountWithMonth(@PathVariable("loanId")String loanId,@PathVariable("month")String month){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallCountWithMonth(loanId,month));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	/**
	 * 陌生号码统计
	 * wanggang
	 * @return
	 */
	@RequestMapping("getStrangerNumberStatistics/{loanId}")
	public MarvelsResultDTO getStrangerNumberStatistics(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			String userId = mcamLoanApplyInfoCommonDao.selectApplyInfoByLoanId(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getStrangerNumberStatistics(loanId,userId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 *通话时间段分析
	 *	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallPeriodStatistics/{loanId}")
	public MarvelsResultDTO getCallPeriodStatistics(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallPeriodStatistics(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}

	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallPeriodStatisticsWithMonth/{loanId}/{month}")
	public MarvelsResultDTO getCallPeriodStatisticsWithMonth(@PathVariable("loanId")String loanId,@PathVariable("month")String month){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallPeriodStatisticsWithMonth(loanId,month));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @retur
	 */
	@RequestMapping("queryCallCountList")
	public MarvelsResultDTO queryCallCountList(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());
		try {
			String userId = mcamLoanApplyInfoCommonDao.selectApplyInfoByLoanId(loanId);
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("userId", userId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			CreditReportMessageDto dto = thirdCreditReportService.queryCallCountList(map);
			PageInfo<CallCountDto> pageInfo = new PageInfo<CallCountDto>((List<CallCountDto> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("queryCallCountListWithMonth")
	public MarvelsResultDTO queryCallCountListWithMonth(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());
		try {
			String userId = mcamLoanApplyInfoCommonDao.selectApplyInfoByLoanId(loanId);
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("userId", userId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			CreditReportMessageDto dto = thirdCreditReportService.queryCallCountListWithMonth(map);
			PageInfo<CallCountDto> pageInfo = new PageInfo<CallCountDto>((List<CallCountDto> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getCallDetailList")
	public MarvelsResultDTO getCallDetailList(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());
		try {
			String userId = mcamLoanApplyInfoCommonDao.selectApplyInfoByLoanId(loanId);
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("userId", userId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			CreditReportMessageDto dto = thirdCreditReportService.getCallDetailList(map);
			PageInfo<IntMxCallDetails> pageInfo = new PageInfo<IntMxCallDetails>((List<IntMxCallDetails> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getAddressBookList")
	public MarvelsResultDTO getAddressBookList(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());

		try {
			String userId = mcamLoanApplyInfoCommonDao.selectApplyInfoByLoanId(loanId);
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("userId", userId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			
			CreditReportMessageDto dto = thirdCreditReportService.getAddressBookList(map);
			PageInfo<IntMxCallDetails> pageInfo = new PageInfo<IntMxCallDetails>((List<IntMxCallDetails> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 *  下载通讯录
	 * @param creditRepotOperatorDto
	 * @param request
	 * @param response
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("downAddressBookList/{loanId}")
	public void downAddressBookList(@PathVariable("loanId")String loanId, 
			HttpServletRequest request, HttpServletResponse response){
		OutputStream os = null;
		try {
			loanId = thirdCreditReportService.getThirdLoanId(loanId);
			McamLoanApplyInfoDTO mcamLoanApplyInfoDTO = mcamLoanApplyInfoService.findMcamLoanApplyInfo(loanId);
			Map<String,Object> map = new HashMap<>();
			map.put("userId", mcamLoanApplyInfoDTO.getCustCode());
			response.setCharacterEncoding("UTF-8");
			response.setContentType("application/vnd.ms-excel");
			List<IntMxCallDetails> list = intMxCallDetailsMapper.downAddressBookList(map);
			HSSFWorkbook wb = new HSSFWorkbook();
			HSSFSheet sheet = wb.createSheet("通讯录");
			HSSFRow row = sheet.createRow((int) 0);
			sheet.setDefaultColumnWidth(10);
			// 创建单元格，并设置值表头 设置表头居中
			HSSFCellStyle style = wb.createCellStyle();
			// 居中格式、加粗
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			HSSFFont font = wb.createFont();
			font.setFontHeightInPoints((short) 11);
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			style.setBorderBottom((short) 1);// 下边框
			style.setBorderLeft((short) 1);// 左边框
			style.setBorderRight((short) 1);// 右边框
			style.setBorderTop((short) 1);// 上边框
			style.setLocked(true);
			style.setFont(font);
			// 设置表内容格式
			HSSFCellStyle style2 = wb.createCellStyle();
			style2.setBorderBottom((short) 1);// 下边框
			style2.setBorderLeft((short) 1);// 左边框
			style2.setBorderRight((short) 1);// 右边框
			style2.setBorderTop((short) 1);// 上边框
			style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			HSSFCell cell = row.createCell(0);
			cell.setCellValue("通讯录名字");
			cell.setCellStyle(style);
			cell = row.createCell(1);
			cell.setCellValue("通讯录号码");
			cell.setCellStyle(style);
			if (list != null && list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					IntMxCallDetails intMxCallDetails = list.get(i);
					row = sheet.createRow((int) i + 1);
					// 创建单元格，并设置值
					row.createCell(0).setCellValue(intMxCallDetails.getName());
					row.createCell(1).setCellValue(intMxCallDetails.getPeerNumber());
					for (int j = 0; j < 2; j++) {
						row.getCell(j).setCellStyle(style2);
					}
				}
			}
			os = response.getOutputStream();// 取得输出流        
	        response.setHeader("Content-disposition", "attachment; filename="+ new String((mcamLoanApplyInfoDTO.getCustName() + " 通讯录.xls").getBytes("UTF-8"), "ISO8859-1"));  
	        response.setContentType("application/x-download");// 定义输出类型      
	        wb.write(os);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("导出excel异常！", e);
		} finally{
			 if (os != null) {
	             try { 
	            	 os.close(); 
	            }  catch (IOException e) { 
	                 MarvelsLogUtil.getInstance().error("关闭流异常！",e);
	            } 
	         } 
		}
	}
	
	@RequestMapping("getMxAlipayUserInfo/{loanId}")
	public MarvelsResultDTO getMxAlipayUserInfo(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);

		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxAlipayUserInfo(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxAlipayBankList/{loanId}")
	public MarvelsResultDTO getMxAlipayBankList(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);

		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxAlipayBankList(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxAlipayAddressList/{loanId}")
	public MarvelsResultDTO getMxAlipayAddressList(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);

		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxAlipayAddressList(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getZXBasicInfo/{loanId}")
	public MarvelsResultDTO getZXBasicInfo(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);

		try {
			LoanApplyCaseDTO dto = loanApplyCaseService.findLoanApplyCase(loanId);
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getZXBasicInfo(dto.getCustCardNo()));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getZXNewCredit/{loanId}")
	public MarvelsResultDTO getZXNewCredit(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getZXNewCredit(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取上海资信新版报告异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxCheckBlackInfo/{loanId}")
	public MarvelsResultDTO getMxCheckBlackInfo(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);

		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxCheckBlackInfo(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	@RequestMapping("getZXApplyInfo")
	public MarvelsResultDTO getZXApplyInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());

		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			
			
			LoanApplyCaseDTO dto = loanApplyCaseService.findLoanApplyCase(creditRepotOperatorDto.getLoanId());
			CreditReportPortrait  creditReportPortrait  = thirdCreditReportService.getZXBasicInfo(dto.getCustCardNo());
			map.put("reqNo", creditReportPortrait.getReqNo());
			CreditReportMessageDto dto1 = thirdCreditReportService.getZXApplyInfo(map);
			PageInfo<ZXPersonalLoanApplyInfo> pageInfo = new PageInfo<ZXPersonalLoanApplyInfo>((List<ZXPersonalLoanApplyInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getSharedPlatformInfo")
	public MarvelsResultDTO getSharedPlatformInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String, Object> map= loanApplyCaseService.getSharedPlatformInfo(creditRepotOperatorDto.getLoanId());
			List<Map<String, Object>> list=new ArrayList<Map<String, Object>>();
			list.add(map);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),list);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>获取共享平台数据异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	@RequestMapping("getZXOrderInfo")
	public MarvelsResultDTO getZXOrderInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());

		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			
			
			LoanApplyCaseDTO dto = loanApplyCaseService.findLoanApplyCase(creditRepotOperatorDto.getLoanId());
			CreditReportPortrait  creditReportPortrait  = thirdCreditReportService.getZXBasicInfo(dto.getCustCardNo());
			map.put("reqNo", creditReportPortrait.getReqNo());
			CreditReportMessageDto dto1 = thirdCreditReportService.getZXOrderInfo(map);
			PageInfo<ZXPersonalLoanOrderInfo> pageInfo = new PageInfo<ZXPersonalLoanOrderInfo>((List<ZXPersonalLoanOrderInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getZXOrderDetailInfo")
	public MarvelsResultDTO getZXOrderDetailInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());

		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", loanId);
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			
			
			LoanApplyCaseDTO dto = loanApplyCaseService.findLoanApplyCase(creditRepotOperatorDto.getLoanId());
			CreditReportPortrait  creditReportPortrait  = thirdCreditReportService.getZXBasicInfo(dto.getCustCardNo());
			map.put("reqNo", creditReportPortrait.getReqNo());
			CreditReportMessageDto dto1 = thirdCreditReportService.getZXOrderDetailInfo(map);
			PageInfo<ZXpersonalLoanOrderDetailsInfo> pageInfo = new PageInfo<ZXpersonalLoanOrderDetailsInfo>((List<ZXpersonalLoanOrderDetailsInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}

	@RequestMapping("getMxUserSearchInfo/{loanId}")
	public MarvelsResultDTO getMxUserSearchInfo(@PathVariable("loanId")String loanId){
		loanId = thirdCreditReportService.getThirdLoanId(loanId);

		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxUserSearchInfo(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 陌生号码统计
	 * wanggang
	 * @return
	 */
	@RequestMapping("getDeviceInfo/{loanId}")
	public MarvelsResultDTO getDeviceInfo(@PathVariable("loanId")String loanId){
		//loanId = thirdCreditReportService.getThirdLoanId(loanId);
		Map<String,Object> map = new HashMap<>();
		map.put("loanId", loanId);
		map.put("mobile", mcamLoanApplyInfoCommonDao.selectMobileByLoanId(loanId));
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getDeviceInfo(map));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getDeviceDetailInfo")
	public MarvelsResultDTO getDeviceDetailInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		//String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());

		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("mobile", mcamLoanApplyInfoCommonDao.selectMobileByLoanId(creditRepotOperatorDto.getLoanId()));
			
			CreditReportMessageDto dto1 = thirdCreditReportService.getDeviceDetailInfo(map);
			PageInfo<ZXpersonalLoanOrderDetailsInfo> pageInfo = new PageInfo<ZXpersonalLoanOrderDetailsInfo>((List<ZXpersonalLoanOrderDetailsInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("selectYDUserInfoDto/{loanId}")
	public MarvelsResultDTO selectYDUserInfoDto(@PathVariable String loanId){
		//String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectYDUserInfoDto(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("selectYDLendBehaviorDto/{loanId}")
	public MarvelsResultDTO selectYDLendBehaviorDto(@PathVariable String loanId){
		//String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectYDLendBehaviorDto(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("selectYDDeviceLinkDto/{loanId}")
	public MarvelsResultDTO selectYDDeviceLinkDto(@PathVariable String loanId){
		//String loanId = thirdCreditReportService.getThirdLoanId(creditRepotOperatorDto.getLoanId());
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectYDDeviceLinkDto(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 征信任务    上传      通用列表     基于 curNodeCode区分
	 * @param param
	 * @return
	 */
	@RequestMapping("list")
	public MarvelsResultDTO list(@RequestBody LoanApplyCaseDTO param){
		MarvelsLogUtil.getInstance().info("入参"+param);
		PageInfo<LoanApplyCaseDTO> pageInfo = null;
		try {
			pageInfo = creditReportService1.getPageInfoByCondition(param);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	
	/**
	 * 征信报告查询
	 * @param param
	 * @return
	 */
	@RequestMapping("queryCreditList")
	public MarvelsResultDTO queryCreditList(@RequestBody LoanApplyCaseDTO loanApplyCaseDTO){
		PageInfo<LoanApplyCaseDTO> pageInfo = null;
		try {
			List<LoanApplyCaseDTO> cases = creditReportService1.findCreditList(loanApplyCaseDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), cases);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	/**
	 * 征信报告否决查询
	 * @param param
	 * @return
	 */
	@RequestMapping("creditList")
	public MarvelsResultDTO creditList(@RequestBody LoanApplyCaseDTO param){
		PageInfo<LoanApplyCaseDTO> pageInfo = null;
		try {
			pageInfo = creditReportService1.getPageInfoByCondition(param);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	
	/**
	 * 征信报告审核列表信息
	 * @param param
	 * @return
	 */
	@RequestMapping("approveList")
	public MarvelsResultDTO approveList(@RequestBody LoanApplyCaseDTO param){
		MarvelsLogUtil.getInstance().info("入参"+param);
		PageInfo<LoanApplyCaseDTO> pageInfo = null;
		Map<String,Object> dataMap = null;
		try {
			dataMap = new HashMap<String,Object>();
			param.setAssignee(param.obtainLoginUserName());
			pageInfo = creditReportService1.getPageInfoByCondition(param);
			//查询征信审核节点待取件数量
			Integer waitCount =creditReportService1.getWaitForDealCount(param);
			dataMap.put("pageInfo", pageInfo);
			//待处理单子数量
			dataMap.put("waitCount", waitCount);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), dataMap);
	}
	/**
	 * 征信前置核录列表
	 * @param param
	 * @return
	 */
	@RequestMapping("creReportBeforeList")
	public MarvelsResultDTO creReportBeforeList(@RequestBody LoanApplyCaseDTO param){
		Map<String,Object> dataMap = null;
		try {
			dataMap = creditReportService1.creReportBeforeList(param);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("征信前置核录查询列表异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), dataMap);
	}
	/**
	 * 已完成的征信前置核录列表
	 * @param param
	 * @return
	 */
	@RequestMapping("finishCreReportBeforeList")
	public MarvelsResultDTO finishCreReportBeforeList(@RequestBody LoanApplyCaseDTO param){
		PageInfo<LoanApplyCaseDTO> pageInfo = null;
		try {
			param = param==null?new LoanApplyCaseDTO():param;
			param.setCurNodeCode(CaseNodeConstant.WOCHECKINGBEFORE.getCode());
			pageInfo = creditReportService1.getApproveFinishList(param);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("征信前置核录查询已完成的列表异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	
	/**
	 * 查询已审核完成列表
	 * @param param
	 * @return
	 */
	@RequestMapping("approveFinishList")
	public MarvelsResultDTO approveFinishList(@RequestBody LoanApplyCaseDTO param){
		PageInfo<LoanApplyCaseDTO> pageInfo = null;
		try {
			param = param==null?new LoanApplyCaseDTO():param;
			param.setCurNodeCode(CaseNodeConstant.WOCREDITCHECK.getCode());
			pageInfo = creditReportService1.getApproveFinishList(param);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	
	
	/**
	 * 获取贷款用户征信基本信息
	 * @param param
	 * @return
	 */
	@RequestMapping("userInfo")
	public MarvelsResultDTO userInfo(@RequestParam("loanId") String  loanId){
		Map<String, Object> dataMap = null; 
		try {
			dataMap = creditReportService1.getUserCreditInfo(loanId);
		} catch (MarvelsBusinessException e) {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), dataMap);
	}
	
	/**
	 * 下载影像资料
	 * @param loanId
	 * @return
	 * @throws MarvelsBusinessException 
	 */
	@RequestMapping("downLoadMedia")
	public void downLoadMedia(@RequestParam("loanId") String  loanId,HttpServletRequest request, HttpServletResponse response) throws MarvelsBusinessException{
		creditReportService1.downLoadMedia(loanId,request,response);
	}

	/**
	 * 提交当前进件到(woCreditLoadUp)节点
	 * @param loanId
	 * @return
	 */
	@RequestMapping("commitToUpload")
	public MarvelsResultDTO commitToUpload(@RequestBody LoanApplyCaseDTO param){
		String loanId = param.getLoanId();
		try {
			LoanApplyCaseDTO caseInfo = creditReportService1.getUserBaseInfoByNodeCode(loanId,CaseNodeConstant.WOCREDITINSPECTION.getCode());
			creditReportService1.commitToNextNode(caseInfo);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	/**
	 * 征信退回 APP
	 * @param param
	 * @return
	 */
	@RequestMapping("chargeBack")
	public MarvelsResultDTO chargeBack(@RequestBody McamLoanApplyInfoDTO param){
		try {
			creditReportService1.chargeBack(param,MarvelsConstant.PROCESS_RESULT_RETURN_APP,LoanStateConstant.Z82);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	
	/**
	 * 征信报告上传
	 * @param file
	 * @return
	 */
	@RequestMapping("reportUpload")
	public MarvelsResultDTO creditReportUpload(@RequestParam("file")MultipartFile file,@RequestParam("loanId") String loanId){
		try {
			InputStream uploadStream = null;
			uploadStream = file.getInputStream();
			String fileName = file.getOriginalFilename();
			if(!fileName.endsWith(".pdf")){
				return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),"请上传PDF格式的文件", null);
			}	
			creditReportService1.creditReportUpload(uploadStream,loanId);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	
	/**
	 * 单子否决
	 * @param param
	 * @return
	 */
	@RequestMapping("vetoCase")
	public MarvelsResultDTO vetoCase(@RequestBody LoanApplyCaseDTO param){
		try {
			creditReportService1.vetoCase(param);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	
	/**
	 * 征信任务    上传    审核   通用取件方法  基于curNodeCode区分
	 * @param loanId
	 * @return
	 */
	@RequestMapping("getTask")
	public MarvelsResultDTO getTask(@RequestBody LoanApplyCaseDTO param){
		HandleProcessDTO handleProcessDTO = new HandleProcessDTO();
		List<String> queryNodes  = new ArrayList<String>();
		queryNodes.add(param.getCurNodeCode());
		handleProcessDTO.setQueryNodes(queryNodes);
		try {
			creditReportService1.handleProcess(handleProcessDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	
	/**
	 * 导出征信excel
	 * @param param
	 * @param request
	 * @param response
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("downloadCreditExcel")
	public void downloadCreditExcel(CreditExcelDTO param,HttpServletRequest request, HttpServletResponse response){
		//String custName,String custCardNo, String productName,Date startCreatedDate,Date endCreatedDate
		OutputStream os = null;
		HSSFWorkbook workbook = null;
		try {
			workbook = creditReportService1.downloadCreditExcel(param,request,response);
	        os = response.getOutputStream();// 取得输出流        
	        response.setHeader("Content-disposition", "attachment; filename="+ new String("征信数据一览表.xls".getBytes("UTF-8"),"ISO8859-1"));  
	        // 设定输出文件头        
	        response.setContentType("application/x-download");// 定义输出类型      
	        workbook.write(os);
	        // response.reset();// 清空输出流        
	      
		}catch(MarvelsBusinessException e){
			MarvelsLogUtil.getInstance().error("导出excel异常！", e);
		} catch (IOException e) {
			MarvelsLogUtil.getInstance().error("导出excel异常！", e);
//			throw new MarvelsBusinessException("导出excel异常！");
		}finally{
			  // os.close();
			 if (os != null) {
                 try { 
                	 os.close(); 
                }  catch (IOException e) { 
	                 MarvelsLogUtil.getInstance().error("关闭流异常！",e);
                } 
             } 
		}
	}
	
	/**
	 * 征信前置录入提交
	 * @param param
	 * @return
	 */
	@RequestMapping("submitCirculation")
	@ResponseBody
	public MarvelsResultDTO submitCirculation(@RequestBody LoanApplyCaseDTO param){
		Integer count;
		try {
			count = creditReportService1.submitCirculation(param);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("征信前置核录提交异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), count);
	}
	/**
	 * 征信前置上传附件
	 * @param file
	 * @param loanId
	 * @return
	 * @throws MarvelsBusinessException
	 */
	@RequestMapping("uploadFile")
	@ResponseBody
	public MarvelsResultDTO uploadFile(@RequestParam("file")MultipartFile file,@RequestParam("loanId") String loanId,@RequestParam("atmtTypeName") String atmtTypeName,@RequestParam("AtmtType") String AtmtType) throws MarvelsBusinessException{
		try {
			creditReportService1.uploadFile(file,loanId,atmtTypeName,AtmtType);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("征信前置录入上传附件异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	/**
	 * 征信前置录入退回
	 * @param param
	 * @return
	 */
	@RequestMapping("returnBack")
	public MarvelsResultDTO returnBack(@RequestBody McamLoanApplyInfoDTO param){
		try {
			creditReportService1.chargeBack(param,MarvelsConstant.PROCESS_RESULT_RETURN, LoanStateConstant.J07);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("征信前置录入退回异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
	}
	
	
	
	/**
	 * 保单截屏数据 状态 J07     基于 curNodeCode区分
	 * @param param
	 * @return
	 */
	@RequestMapping("getScreenshotsList")
	@ResponseBody
	public MarvelsResultDTO getScreenshotsLis(@RequestBody ScreenshotsDTO param){
		MarvelsLogUtil.getInstance().info("入参"+param);
		PageInfo<ScreenshotsDTO> pageInfo = null;
		try {
			pageInfo = creditReportService1.getScreenshotsList(param);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), pageInfo);
	}
	/**
	 * 保单截屏拒绝方法
	 * @param param
	 * @return
	 */
	@RequestMapping("refusedDate")
	@ResponseBody
	public MarvelsResultDTO refusedDate(@RequestBody ScreenshotsDTO param){
		try {
			Integer count = creditReportService1.refusedDate(param);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), count);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
		
	}
	/**
	 * 保单截屏中保存功能，只检查有没有截屏数据，
	 * 没有数据则提示
	 * @param param
	 * @return
	 */
	@RequestMapping("submitDate")
	@ResponseBody
	public MarvelsResultDTO submitDate(@RequestBody ScreenshotsDTO params){
		try {
			Integer count = creditReportService1.submitDate(params);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), count);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**
	 * 获取当前支持的所有类型的附件信息
	 * @param loanId
	 * @return
	 */
	@RequestMapping("getAttachmentsByViewKey")
	@ResponseBody
	public MarvelsResultDTO getAttachmentsByViewKey(@RequestParam("loanId") String loanId){
		List<LaAttachAtmeTypeViewDTO> data = null;
		try {
			data = creditReportService1.getAttachmentsByViewKey(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), data);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e);
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e);
		}
	}
	
	
	
	/**
	 * 查询短信
	 * @param edcBurialPointMsgDTO
	 * @return
	 */
	@RequestMapping("getBurialPointMsg")
	@ResponseBody
	public MarvelsResultDTO getBurialPointMsg(@RequestBody EdcBurialPointMsgDTO edcBurialPointMsgDTO){
		try {
			Page<EdcBurialPointMsgDTO> list = creditReportService1.getBurialPointMsg(edcBurialPointMsgDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), list);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>loanId"+edcBurialPointMsgDTO.getLoanId()+"查询短信失败", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e);
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>loanId"+edcBurialPointMsgDTO.getLoanId()+"查询短信异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e);
		}
	}
}
